package com.org.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.validator.GenericValidator;

/**
 * 登陆action
 * Created by GYM on 14-3-30.
 */
public class LoginAction extends ActionSupport {

    private String username;

    private String password;

    public String login(){
        System.out.println("userName:"+username+"///"+"password:"+password);
        if(username.startsWith("a")&&"123".equals(password)){
            return this.SUCCESS;
        }else{
            this.addActionError("用户名密码错误");
            return this.ERROR;
        }
    }

    @Override
    public void validate() {
        if (GenericValidator.isBlankOrNull(username)){
            this.addFieldError("username","用户名不能为空");
        }
        if(GenericValidator.isBlankOrNull(password)){
            this.addFieldError("password","密码不能为空");
        }
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }
}
